// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_PRE_RECEIVED_ORDER
// * CreateDate    : 2011/8/16 10:16:40
// * Creater       : CodeSmith
// * LastChangeDate: 2011/8/16 10:16:40
// * LastChanger   : 2011/8/16 10:16:40
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;
using ESOL.Business.Mst;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinPreReceivedOrder
    /// </summary>
    public partial class FinPreReceivedOrderBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinPreReceivedOrderEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinPreReceivedOrderEntity GetFinPreReceivedOrder(FinPreReceivedOrderEntity objFinPreReceivedOrderEntity)
        {
            return DataAccess.SelectSingle<FinPreReceivedOrderEntity>(objFinPreReceivedOrderEntity);
        }

        public static FinPreReceivedOrderEntity GetByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            FinPreReceivedOrderEntity entity = new FinPreReceivedOrderEntity();
            entity.PreReceivedOrderId = id;
            return DataAccess.SelectSingle<FinPreReceivedOrderEntity>(entity);
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"RO.*, C.CUSTOMER_NAME, P.NAME_CN
                                FROM FIN_PRE_RECEIVED_ORDER RO
								LEFT JOIN SALES_PROD_PLAN_APPLICATION PPA ON PPA.APPLICATION_ID = RO.APPLICATION_ID
                                LEFT JOIN MST_CUSTOMER C ON C.CUSTOMER_ID = PPA.CUSTOMER_ID
                                LEFT JOIN MST_PERSON P ON P.PERSON_ID = RO.INVOICE_PERSON
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinPreReceivedOrderEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinPreReceivedOrder(FinPreReceivedOrderEntity objFinPreReceivedOrderEntity)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    string code = "";
                    if (MstCodeRuleBs.GetCurrentOrderCode("PreReceivedOrder", out code, broker) == false)
                    {
                        broker.RollBack();
                        return false;
                    }
                    objFinPreReceivedOrderEntity.InvoiceCode = code;
                    DataAccess.Insert(objFinPreReceivedOrderEntity, broker);

                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static bool InsertFinPreReceivedOrder(List<FinPreReceivedOrderEntity> objFinPreReceivedOrderEntityList)
        {
            return DataAccess.Insert(objFinPreReceivedOrderEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinPreReceivedOrderEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinPreReceivedOrder(FinPreReceivedOrderEntity objFinPreReceivedOrderEntity)
        {
            return DataAccess.Update(objFinPreReceivedOrderEntity);
        }

        public static bool UpdateFinPreReceivedOrder(List<FinPreReceivedOrderEntity> objFinPreReceivedOrderEntityList)
        {
            return DataAccess.Update<FinPreReceivedOrderEntity>(objFinPreReceivedOrderEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinPreReceivedOrderEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinPreReceivedOrder(FinPreReceivedOrderEntity objFinPreReceivedOrderEntity)
        {
            return DataAccess.Delete(objFinPreReceivedOrderEntity);
        }

        public static bool DeleteFinPreReceivedOrder(List<FinPreReceivedOrderEntity> objFinPreReceivedOrderEntityList)
        {
            return DataAccess.Delete<FinPreReceivedOrderEntity>(objFinPreReceivedOrderEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinPreReceivedOrderAll()
        {
            return DataAccess.SelectAllDataSet<FinPreReceivedOrderEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinPreReceivedOrderEntity> GetFinPreReceivedOrderAllList()
        {
            return DataAccess.SelectAll<FinPreReceivedOrderEntity>();
        }
        #endregion
	}
}	

